]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageList: Limit body/title length
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 4 Sep 2026 18:45:23 +0000 (20:45 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Sun, 13 Sep 2026 17:39:10 +0000 (19:39 +0200)
The strings typically come from apps, and can therefore be of
arbitrary length.

Excessively long strings will end up ellsized, but they still
affect performance when computing the Pango layout or searching
for URLs, as those operate on the entire string.

Address this by imposing a character limit on the strings, so that
the amount of hidden characters to consider for URLs and layout is
capped.

The picked limits are based on sequences of "l", which should be more
dense than any real text, and therefore guarantee that we only cut
off invisible parts of the strings.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4387>
(cherry picked from commit 336a4b3c58ecef1b50e147eafa92fd21633604b1)

js/ui/messageList.js

index cf9e501d05d7220f6514677dc02b46eeb7b3daac..38ae640e6cce5a4bd4c30fad713621954ec31177 100644 (file)
@@ -30,6 +30,9 @@ const WIDTH_OFFSET_STACKED = 6;
 const HEIGHT_OFFSET_STACKED = 10;
 const HEIGHT_OFFSET_REDUCTION_STACKED = 1.4;
 
+const MAX_TITLE_LENGTH = 150;
+const MAX_BODY_LENGTH = 850;
+
 export const URLHighlighter = GObject.registerClass(
 class URLHighlighter extends St.Label {
     _init(text = '', lineWrap, allowMarkup) {
@@ -564,7 +567,7 @@ export const Message = GObject.registerClass({
     }
 
     set title(text) {
-        this._titleText = text;
+        this._titleText = this._limitString(text, MAX_TITLE_LENGTH);
         const title = text ? Util.fixMarkup(text.replace(/\n/g, ' '), false) : '';
         this.titleLabel.clutter_text.set_markup(title);
         this.notify('title');
@@ -575,7 +578,7 @@ export const Message = GObject.registerClass({
     }
 
     set body(text) {
-        this._bodyText = text;
+        this._bodyText = this._limitString(text, MAX_BODY_LENGTH);
         this._bodyLabel.setMarkup(text ? text.replace(/\n/g, ' ') : '',
             this._useBodyMarkup);
         this.notify('body');
@@ -684,6 +687,15 @@ export const Message = GObject.registerClass({
         }
         return super.vfunc_key_press_event(event);
     }
+
+    _limitString(string, limit) {
+        const segmenter = new Intl.Segmenter();
+        const graphemes =
+            Array.from(segmenter.segment(string))
+            .splice(0, limit)
+            .map(o => o.segment);
+        return graphemes.join('');
+    }
 });
 
 export const NotificationMessage = GObject.registerClass(